// 步骤3.1: 在js文件夹下新建一个api.js文件，用于存放API请求的函数。
// 在api.js文件中，导入axios，并且导出一个对象，对象中包含了所有的API请求函数。

// 步骤3.2: 在api.js文件中，定义一个API_URL常量，用于存放API的地址。
// 知识点：通过const定义常量，常量的值不能被修改。
//const API_URL = 'http://mockjs'; // xxx是你的 API 地址，例如：'http://mockjs'用于测试
const API_URL = 'http://localhost:8080/MyApp'; 

// 步骤3.3: 在api.js文件中，定义一个对象，对象中包含了所有的API请求函数。
// 知识点：export default用于通过默认导出方式导出一个对象，可以在其它js文件中通过 import xxx from ./api.js'导入使用。
export default {
  // 订单 API
  getOrders: (userId, params) => axios.get(`${API_URL}/orders/${userId}`, { params: params }),
  // getOrdersByStatus: (userId, status) => axios.get(`${API_URL}/orders/${userId}`, { status: status }),
  getOrdersByStatus: (userId, status) => axios.get(`${API_URL}/orders/${userId}?status=${status}`), 
  createOrder: (userId) => axios.post(`${API_URL}/orders`, { userId: userId }),
  getOrder: (orderId) => axios.get(`${API_URL}/orders/${orderId}`),
  updateOrderStatus: (orderId, status) => axios.put(`${API_URL}/orders/${orderId}`, {status: status}),

  // 订单菜品 API
  getOrderDishes: (orderId) => axios.get(`${API_URL}/orderDishes/${orderId}`),
  addOrderDish: (orderId, dishId) => axios.post(`${API_URL}/orderDishes/${orderId}`, { dishId: dishId }),
  updateOrderDish: (orderId, dishId, quantity) => axios.put(`${API_URL}/orderDishes/${orderId}/dishes/${dishId}`, { quantity: quantity }),  
  deleteOrderDish: (orderId, dishId) => axios.delete(`${API_URL}/orderDishes/${orderId}/dishes/${dishId}`),

  // 用户 API
  registerUser: (user) => axios.post(`${API_URL}/users/register`, user),
  loginUser: (user) => axios.post(`${API_URL}/users/login`, user),
  getUser: (userId) => axios.get(`${API_URL}/users/${userId}`),
  updateUser: (userId, user) => axios.put(`${API_URL}/users/${userId}`, user),

  // 菜品 API
  getDishes: () => axios.get(`${API_URL}/dishes`),
  createDish: (dish) => axios.post(`${API_URL}/dishes`, dish),
  getDish: (dishId) => axios.get(`${API_URL}/dishes/${dishId}`),
  updateDish: (dishId, dish) => axios.put(`${API_URL}/dishes/${dishId}`, dish),
};